using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
    public class LIST_CMDDataAccess : Connection
    {
		#region Local Variable
        private string _strSPInsertName = "dbo.[procLIST_CMD_add]";
        private string _strSPUpdateName = "dbo.[procLIST_CMD_update]";
        private string _strSPDeleteName = "dbo.[procLIST_CMD_delete]";
        private string _strSPGetName = "dbo.[procLIST_CMD_get]";
        private string _strSPGetAllName = "dbo.[procLIST_CMD_getall]";
		private string _strSPGetPages = "dbo.[procLIST_CMD_getpaged]";
		private string _strSPIsExist = "dbo.[procLIST_CMD_isexist]";
        private string _strTableName = "[LIST_CMD]";
		private string _strSPGetTransferOutName = "dbo.[procLIST_CMD_gettransferout]";
		#endregion Local Variable
		
		#region Method
        public LIST_CMDInfo Get(
        String DTB,
        String CmdID,
		ref string sErr)
        {
			LIST_CMDInfo objEntr = new LIST_CMDInfo();
            InitConnect();
			InitSPCommand(_strSPGetName);              
            AddParameter(LIST_CMDInfo.Field.DTB.ToString(), DTB);
            AddParameter(LIST_CMDInfo.Field.CmdID.ToString(), CmdID);
            
            DataTable list = new DataTable();
            try
            {
                list = executeSelect();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}  
            
            if (list.Rows.Count > 0)
                objEntr = (LIST_CMDInfo)GetDataFromDataRow(list, 0);
            //if (dr != null) list = CBO.FillCollection(dr, ref list);
            if (sErr != "") ErrorLog.SetLog(sErr);
            return objEntr;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            LIST_CMDInfo result = new LIST_CMDInfo();
            result.DTB = (dt.Rows[i][LIST_CMDInfo.Field.DTB.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.DTB.ToString()]));
            result.CmdID = (dt.Rows[i][LIST_CMDInfo.Field.CmdID.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.CmdID.ToString()]));
            result.Description = (dt.Rows[i][LIST_CMDInfo.Field.Description.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.Description.ToString()]));
            result.Suspend = (dt.Rows[i][LIST_CMDInfo.Field.Suspend.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.Suspend.ToString()]));
            result.CmdGroup = (dt.Rows[i][LIST_CMDInfo.Field.CmdGroup.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.CmdGroup.ToString()]));
            result.Context = (dt.Rows[i][LIST_CMDInfo.Field.Context.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.Context.ToString()]));
            result.CallingP = (dt.Rows[i][LIST_CMDInfo.Field.CallingP.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.CallingP.ToString()]));
            result.DAOG = (dt.Rows[i][LIST_CMDInfo.Field.DAOG.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.DAOG.ToString()]));
            result.CmdText = (dt.Rows[i][LIST_CMDInfo.Field.CmdText.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.CmdText.ToString()]));
            result.Template = (dt.Rows[i][LIST_CMDInfo.Field.Template.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.Template.ToString()]));
            result.Range = (dt.Rows[i][LIST_CMDInfo.Field.Range.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.Range.ToString()]));
            result.CONN_ID = (dt.Rows[i][LIST_CMDInfo.Field.CONN_ID.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.CONN_ID.ToString()]));
            result.IsSave = (dt.Rows[i][LIST_CMDInfo.Field.IsSave.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.IsSave.ToString()]));
            result.IsRefresh = (dt.Rows[i][LIST_CMDInfo.Field.IsRefresh.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.IsRefresh.ToString()]));
            result.P1 = (dt.Rows[i][LIST_CMDInfo.Field.P1.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P1.ToString()]));
            result.P2 = (dt.Rows[i][LIST_CMDInfo.Field.P2.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P2.ToString()]));
            result.P3 = (dt.Rows[i][LIST_CMDInfo.Field.P3.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P3.ToString()]));
            result.P4 = (dt.Rows[i][LIST_CMDInfo.Field.P4.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P4.ToString()]));
            result.P5 = (dt.Rows[i][LIST_CMDInfo.Field.P5.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P5.ToString()]));
            result.P6 = (dt.Rows[i][LIST_CMDInfo.Field.P6.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P6.ToString()]));
            result.P7 = (dt.Rows[i][LIST_CMDInfo.Field.P7.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P7.ToString()]));
            result.P8 = (dt.Rows[i][LIST_CMDInfo.Field.P8.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P8.ToString()]));
            result.P9 = (dt.Rows[i][LIST_CMDInfo.Field.P9.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P9.ToString()]));
            result.P10 = (dt.Rows[i][LIST_CMDInfo.Field.P10.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.P10.ToString()]));
            result.L_P1 = (dt.Rows[i][LIST_CMDInfo.Field.L_P1.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P1.ToString()]));
            result.L_P2 = (dt.Rows[i][LIST_CMDInfo.Field.L_P2.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P2.ToString()]));
            result.L_P3 = (dt.Rows[i][LIST_CMDInfo.Field.L_P3.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P3.ToString()]));
            result.L_P4 = (dt.Rows[i][LIST_CMDInfo.Field.L_P4.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P4.ToString()]));
            result.L_P5 = (dt.Rows[i][LIST_CMDInfo.Field.L_P5.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P5.ToString()]));
            result.L_P6 = (dt.Rows[i][LIST_CMDInfo.Field.L_P6.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P6.ToString()]));
            result.L_P7 = (dt.Rows[i][LIST_CMDInfo.Field.L_P7.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P7.ToString()]));
            result.L_P8 = (dt.Rows[i][LIST_CMDInfo.Field.L_P8.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P8.ToString()]));
            result.L_P9 = (dt.Rows[i][LIST_CMDInfo.Field.L_P9.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P9.ToString()]));
            result.L_P10 = (dt.Rows[i][LIST_CMDInfo.Field.L_P10.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.L_P10.ToString()]));
            result.R_P1 = (dt.Rows[i][LIST_CMDInfo.Field.R_P1.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P1.ToString()]));
            result.R_P2 = (dt.Rows[i][LIST_CMDInfo.Field.R_P2.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P2.ToString()]));
            result.R_P3 = (dt.Rows[i][LIST_CMDInfo.Field.R_P3.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P3.ToString()]));
            result.R_P4 = (dt.Rows[i][LIST_CMDInfo.Field.R_P4.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P4.ToString()]));
            result.R_P5 = (dt.Rows[i][LIST_CMDInfo.Field.R_P5.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P5.ToString()]));
            result.R_P6 = (dt.Rows[i][LIST_CMDInfo.Field.R_P6.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P6.ToString()]));
            result.R_P7 = (dt.Rows[i][LIST_CMDInfo.Field.R_P7.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P7.ToString()]));
            result.R_P8 = (dt.Rows[i][LIST_CMDInfo.Field.R_P8.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P8.ToString()]));
            result.R_P9 = (dt.Rows[i][LIST_CMDInfo.Field.R_P9.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P9.ToString()]));
            result.R_P10 = (dt.Rows[i][LIST_CMDInfo.Field.R_P10.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.R_P10.ToString()]));
            result.Notes = (dt.Rows[i][LIST_CMDInfo.Field.Notes.ToString()] == DBNull.Value ? "" : Convert.ToString(dt.Rows[i][LIST_CMDInfo.Field.Notes.ToString()]));
           
            return result;
        }

        public DataTable GetAll(
        String DTB,
        ref string sErr)
        {
            InitConnect();
            InitSPCommand(_strSPGetAllName);
			AddParameter(LIST_CMDInfo.Field.DTB.ToString(), DTB);
            DataTable list = new DataTable();
            try
            {
                list = executeSelect();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}


            if (sErr != "") ErrorLog.SetLog(sErr);
            return list;
        }
		public DataTable GetByPos(
        String DTB,
        int pos, ref string sErr)
        {
            InitConnect();
            InitSPCommand(_strSPGetAllName);
			AddParameter("INX", pos);
			AddParameter(LIST_CMDInfo.Field.DTB.ToString(), DTB);
            DataTable list = new DataTable();
            try
            {
                list = executeSelect();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}


            if (sErr != "") ErrorLog.SetLog(sErr);
            return list;
        }
		public int GetCountRecord(
        String DTB,
        ref string sErr)
        {
			int ret = -1;
            openConnection();
            InitSPCommand(_strSPInsertName);
            AddParameter(LIST_CMDInfo.Field.DTB.ToString(), DTB);
          
            try
            {
                //command.ExecuteNonQuery();
                object tmp = executeScalar();
                if(tmp != null && tmp != DBNull.Value)
					ret = Convert.ToInt32(tmp);
				else 
					ret=0;
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}
            if (sErr != "") ErrorLog.SetLog(sErr);
			
            return ret;			
        }
		/// <summary>
        /// Return 1: Table is exist Identity Field
        /// Return 0: Table is not exist Identity Field
        /// Return -1: Erro
        /// </summary>
        /// <param name="tableName"></param>
        public Int32 Add(LIST_CMDInfo objEntr, ref string sErr)
        {
            int ret = -1;
            openConnection();
            InitSPCommand(_strSPInsertName);
            AddParameter(LIST_CMDInfo.Field.DTB.ToString(), objEntr.DTB);
            AddParameter(LIST_CMDInfo.Field.CmdID.ToString(), objEntr.CmdID);
            AddParameter(LIST_CMDInfo.Field.Description.ToString(), objEntr.Description);
            AddParameter(LIST_CMDInfo.Field.Suspend.ToString(), objEntr.Suspend);
            AddParameter(LIST_CMDInfo.Field.CmdGroup.ToString(), objEntr.CmdGroup);
            AddParameter(LIST_CMDInfo.Field.Context.ToString(), objEntr.Context);
            AddParameter(LIST_CMDInfo.Field.CallingP.ToString(), objEntr.CallingP);
            AddParameter(LIST_CMDInfo.Field.DAOG.ToString(), objEntr.DAOG);
            AddParameter(LIST_CMDInfo.Field.CmdText.ToString(), objEntr.CmdText);
            AddParameter(LIST_CMDInfo.Field.Template.ToString(), objEntr.Template);
            AddParameter(LIST_CMDInfo.Field.Range.ToString(), objEntr.Range);
            AddParameter(LIST_CMDInfo.Field.CONN_ID.ToString(), objEntr.CONN_ID);
            AddParameter(LIST_CMDInfo.Field.IsSave.ToString(), objEntr.IsSave);
            AddParameter(LIST_CMDInfo.Field.IsRefresh.ToString(), objEntr.IsRefresh);
            AddParameter(LIST_CMDInfo.Field.P1.ToString(), objEntr.P1);
            AddParameter(LIST_CMDInfo.Field.P2.ToString(), objEntr.P2);
            AddParameter(LIST_CMDInfo.Field.P3.ToString(), objEntr.P3);
            AddParameter(LIST_CMDInfo.Field.P4.ToString(), objEntr.P4);
            AddParameter(LIST_CMDInfo.Field.P5.ToString(), objEntr.P5);
            AddParameter(LIST_CMDInfo.Field.P6.ToString(), objEntr.P6);
            AddParameter(LIST_CMDInfo.Field.P7.ToString(), objEntr.P7);
            AddParameter(LIST_CMDInfo.Field.P8.ToString(), objEntr.P8);
            AddParameter(LIST_CMDInfo.Field.P9.ToString(), objEntr.P9);
            AddParameter(LIST_CMDInfo.Field.P10.ToString(), objEntr.P10);
            AddParameter(LIST_CMDInfo.Field.L_P1.ToString(), objEntr.L_P1);
            AddParameter(LIST_CMDInfo.Field.L_P2.ToString(), objEntr.L_P2);
            AddParameter(LIST_CMDInfo.Field.L_P3.ToString(), objEntr.L_P3);
            AddParameter(LIST_CMDInfo.Field.L_P4.ToString(), objEntr.L_P4);
            AddParameter(LIST_CMDInfo.Field.L_P5.ToString(), objEntr.L_P5);
            AddParameter(LIST_CMDInfo.Field.L_P6.ToString(), objEntr.L_P6);
            AddParameter(LIST_CMDInfo.Field.L_P7.ToString(), objEntr.L_P7);
            AddParameter(LIST_CMDInfo.Field.L_P8.ToString(), objEntr.L_P8);
            AddParameter(LIST_CMDInfo.Field.L_P9.ToString(), objEntr.L_P9);
            AddParameter(LIST_CMDInfo.Field.L_P10.ToString(), objEntr.L_P10);
            AddParameter(LIST_CMDInfo.Field.R_P1.ToString(), objEntr.R_P1);
            AddParameter(LIST_CMDInfo.Field.R_P2.ToString(), objEntr.R_P2);
            AddParameter(LIST_CMDInfo.Field.R_P3.ToString(), objEntr.R_P3);
            AddParameter(LIST_CMDInfo.Field.R_P4.ToString(), objEntr.R_P4);
            AddParameter(LIST_CMDInfo.Field.R_P5.ToString(), objEntr.R_P5);
            AddParameter(LIST_CMDInfo.Field.R_P6.ToString(), objEntr.R_P6);
            AddParameter(LIST_CMDInfo.Field.R_P7.ToString(), objEntr.R_P7);
            AddParameter(LIST_CMDInfo.Field.R_P8.ToString(), objEntr.R_P8);
            AddParameter(LIST_CMDInfo.Field.R_P9.ToString(), objEntr.R_P9);
            AddParameter(LIST_CMDInfo.Field.R_P10.ToString(), objEntr.R_P10);
            AddParameter(LIST_CMDInfo.Field.Notes.ToString(), objEntr.Notes);
          
            try
            {
                //command.ExecuteNonQuery();
                object tmp = executeScalar();
                if(tmp != null && tmp != DBNull.Value)
					ret = Convert.ToInt32(tmp);
				else 
					ret=0;
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}
            if (sErr != "") ErrorLog.SetLog(sErr);
			
            return ret;
        }

        public string Update(LIST_CMDInfo objEntr)
        {
            openConnection();
            InitSPCommand(_strSPUpdateName);
            AddParameter(LIST_CMDInfo.Field.DTB.ToString(), objEntr.DTB);
            AddParameter(LIST_CMDInfo.Field.CmdID.ToString(), objEntr.CmdID);
            AddParameter(LIST_CMDInfo.Field.Description.ToString(), objEntr.Description);
            AddParameter(LIST_CMDInfo.Field.Suspend.ToString(), objEntr.Suspend);
            AddParameter(LIST_CMDInfo.Field.CmdGroup.ToString(), objEntr.CmdGroup);
            AddParameter(LIST_CMDInfo.Field.Context.ToString(), objEntr.Context);
            AddParameter(LIST_CMDInfo.Field.CallingP.ToString(), objEntr.CallingP);
            AddParameter(LIST_CMDInfo.Field.DAOG.ToString(), objEntr.DAOG);
            AddParameter(LIST_CMDInfo.Field.CmdText.ToString(), objEntr.CmdText);
            AddParameter(LIST_CMDInfo.Field.Template.ToString(), objEntr.Template);
            AddParameter(LIST_CMDInfo.Field.Range.ToString(), objEntr.Range);
            AddParameter(LIST_CMDInfo.Field.CONN_ID.ToString(), objEntr.CONN_ID);
            AddParameter(LIST_CMDInfo.Field.IsSave.ToString(), objEntr.IsSave);
            AddParameter(LIST_CMDInfo.Field.IsRefresh.ToString(), objEntr.IsRefresh);
            AddParameter(LIST_CMDInfo.Field.P1.ToString(), objEntr.P1);
            AddParameter(LIST_CMDInfo.Field.P2.ToString(), objEntr.P2);
            AddParameter(LIST_CMDInfo.Field.P3.ToString(), objEntr.P3);
            AddParameter(LIST_CMDInfo.Field.P4.ToString(), objEntr.P4);
            AddParameter(LIST_CMDInfo.Field.P5.ToString(), objEntr.P5);
            AddParameter(LIST_CMDInfo.Field.P6.ToString(), objEntr.P6);
            AddParameter(LIST_CMDInfo.Field.P7.ToString(), objEntr.P7);
            AddParameter(LIST_CMDInfo.Field.P8.ToString(), objEntr.P8);
            AddParameter(LIST_CMDInfo.Field.P9.ToString(), objEntr.P9);
            AddParameter(LIST_CMDInfo.Field.P10.ToString(), objEntr.P10);
            AddParameter(LIST_CMDInfo.Field.L_P1.ToString(), objEntr.L_P1);
            AddParameter(LIST_CMDInfo.Field.L_P2.ToString(), objEntr.L_P2);
            AddParameter(LIST_CMDInfo.Field.L_P3.ToString(), objEntr.L_P3);
            AddParameter(LIST_CMDInfo.Field.L_P4.ToString(), objEntr.L_P4);
            AddParameter(LIST_CMDInfo.Field.L_P5.ToString(), objEntr.L_P5);
            AddParameter(LIST_CMDInfo.Field.L_P6.ToString(), objEntr.L_P6);
            AddParameter(LIST_CMDInfo.Field.L_P7.ToString(), objEntr.L_P7);
            AddParameter(LIST_CMDInfo.Field.L_P8.ToString(), objEntr.L_P8);
            AddParameter(LIST_CMDInfo.Field.L_P9.ToString(), objEntr.L_P9);
            AddParameter(LIST_CMDInfo.Field.L_P10.ToString(), objEntr.L_P10);
            AddParameter(LIST_CMDInfo.Field.R_P1.ToString(), objEntr.R_P1);
            AddParameter(LIST_CMDInfo.Field.R_P2.ToString(), objEntr.R_P2);
            AddParameter(LIST_CMDInfo.Field.R_P3.ToString(), objEntr.R_P3);
            AddParameter(LIST_CMDInfo.Field.R_P4.ToString(), objEntr.R_P4);
            AddParameter(LIST_CMDInfo.Field.R_P5.ToString(), objEntr.R_P5);
            AddParameter(LIST_CMDInfo.Field.R_P6.ToString(), objEntr.R_P6);
            AddParameter(LIST_CMDInfo.Field.R_P7.ToString(), objEntr.R_P7);
            AddParameter(LIST_CMDInfo.Field.R_P8.ToString(), objEntr.R_P8);
            AddParameter(LIST_CMDInfo.Field.R_P9.ToString(), objEntr.R_P9);
            AddParameter(LIST_CMDInfo.Field.R_P10.ToString(), objEntr.R_P10);
            AddParameter(LIST_CMDInfo.Field.Notes.ToString(), objEntr.Notes);
               
            string sErr = "";
            try
            {
                executeNonQuery();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}
            if (sErr != "") ErrorLog.SetLog(sErr);
            return sErr;
        }

        public string Delete(
        String DTB,
        String CmdID
		)
        {
            openConnection();
            InitSPCommand(_strSPDeleteName);
            AddParameter(LIST_CMDInfo.Field.DTB.ToString(), DTB);
            AddParameter(LIST_CMDInfo.Field.CmdID.ToString(), CmdID);
              
            string sErr = "";
            try
            {
                executeNonQuery();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}
            if (sErr != "") ErrorLog.SetLog(sErr);
            return sErr;
        }   
		
		
        
        public Boolean IsExist(
        String DTB,
        String CmdID
		)
        {
            InitConnect();
            InitSPCommand(_strSPIsExist);
            AddParameter(LIST_CMDInfo.Field.DTB.ToString(), DTB);
            AddParameter(LIST_CMDInfo.Field.CmdID.ToString(), CmdID);
              
            string sErr = "";
            DataTable list = new DataTable();
            try
            {
                list = executeSelect();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}
            if (sErr != "") ErrorLog.SetLog(sErr);
            if(list.Rows.Count==1)
				return true;
            return false;
        }
		
		private string CreateWhereClause(LIST_CMDInfo obj)
        {
            String result = "";

            return result;
        }
        
        public DataTable Search(string columnName, string columnValue, string condition, string tableName, ref string sErr)
        {
            string query = "select * from " + _strTableName + " where " + columnName + " " + condition + " " + columnValue;
            DataTable list = new DataTable();
            openConnection();
            try
            {
                list = executeSelectQuery(query);
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}
            //if (dr != null) list = CBO.FillCollection(dr, ref list);
            //    if (sErr != "") ErrorLog.SetLog(sErr);
            return list;
        }
		public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            InitConnect();
            InitSPCommand(_strSPGetTransferOutName);
			AddParameter("DB", dtb);
			AddParameter("FROM", from);
			AddParameter("TO", to);
            DataTable list = new DataTable();
            try
            {
                list = executeSelect();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            finally {closeConnection();}


            if (sErr != "") ErrorLog.SetLog(sErr);
            return list;
        }
		#endregion Method
     
    }
}
